package org.zfes.snowier.cloud.zbss.metting.router.service.pub;

import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.zfes.snowier.common.file.FileResInfo;
import org.zfes.snowier.common.file.UeditorState;
import org.zfes.snowier.common.file.disk.UploadUitl;
import org.zfes.snowier.core.util.ZAlert;
import org.zfes.snowier.core.util.ZAssert;
import org.zfes.snowier.web.controller.BaseController;

@Controller("org.zfes.snowier.cloud.zbss.metting.router.service.pub.PubUploadController")
@RequestMapping("/met/service/pub/upload")
public class PubUploadController extends BaseController{
	
	@RequestMapping(value="/uploadDoc", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
	public @ResponseBody  Object uploadProjecDoc(@RequestParam(name="file",required=false)MultipartFile file)  {
		ZAssert.notNull(file,"请选择文件");
		 try {
			 FileResInfo resInfo=  UploadUitl.tranferFile(file,"");
			 return ajaxQuery("fileUrl",resInfo.getFileUrl());
		 }catch (Exception e) {
			e.printStackTrace();
			ZAlert.Error("选择上传错误");
		}
		 
		return ajaxQuery("docPath", "");
	}

	
	@RequestMapping(value="/uploadUeditorImg", method = { RequestMethod.POST,  RequestMethod.GET },produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
	public @ResponseBody  Object UploadUeditorImg(@RequestParam(name="upfile",required=false)MultipartFile file)  {
	
		 try {
			 ZAssert.notNull(file,"请选择文件");
			 FileResInfo resInfo =  UploadUitl.tranferFile(file,"");
			 return new UeditorState( "SUCCESS", resInfo.getFileUrl() ).setOriginal(resInfo.getFileOriginName()).setTitle("");
			 
		 }catch (Exception e) {
			e.printStackTrace();
			 return new UeditorState("上传失败").setTitle("上传失败：【"+e.getMessage()+"】");
		}
	}
	
	@RequestMapping(value="/uploadImg", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
	public @ResponseBody  Object uploadImg(@RequestParam(name="file",required=false)MultipartFile file)  {
		ZAssert.notNull(file,"请选择文件");
		 try {
			 FileResInfo resInfo=UploadUitl.tranferFile(file,"");
			 return ajaxQuery("fileUrl",resInfo.getFileUrl());
		 }catch (Exception e) {
			 
			e.printStackTrace();
			ZAlert.Error("选择上传错误");
		}
		 return ajaxQuery("docPath", "");
	}
	
	

}
